import Router from '@koa/router'

const router = new Router({ prefix: '/api/auth' })
import { routerPathConfig } from './routerMap'
import { IConfigFun, mapRecord } from './router-type'

routerPathConfig.forEach((item: mapRecord) => {
  let {type, path, configFun, controllerFun} = item
  router[type](path, async ctx => {
    if ( !configFun ) configFun = (ctx: IConfigFun) => ctx.request.body
    ctx.body = await controllerFun(configFun(ctx))
  })
})

export default router
